/**
 * Project Name:fire-industry-DM-center
 * File Name:ConventerListVO.java
 * Package Name:com.firestone.converters.resource
 * Date:2018年3月29日上午9:08:58
 *
*/

package com.firestone.converters.center;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.baomidou.mybatisplus.plugins.Page;
import com.firestone.bean.dto.resource.ResourceListDTO;
import com.firestone.bean.vo.BaseListVO;
import com.firestone.bean.vo.resource.ResourceVO;
import com.firestone.common.tool.DateUtils;
import com.firestone.core.constants.ConstantMapKey;

/**
 * @Description: TODO(资源控制器里的视图转换)
 * @author CAIYJ
 * @date 2018年3月29日 上午9:08:58
 */
public final class ConverterResource {

    /**
     * @Description: TODO(资源列表视图转换)
     * @param page
     * @return
     * @author CAIYJ
     * @param <T>
     * @date 2018年3月30日 下午1:57:24
     * @lastModifier CAIYJ
     */
    public static final <T> BaseListVO<ResourceVO> convertListVO(
            Page<ResourceListDTO> page) {
        BaseListVO<ResourceVO> vo = new BaseListVO<ResourceVO>();
        if (page != null) {
            if (page.getRecords() != null && page.getRecords().size() > 0) {
                List<ResourceVO> list = new ArrayList<>();
                for (ResourceListDTO resource : page.getRecords()) {
                    ResourceVO resourceVO = new ResourceVO();
                    BeanUtils.copyProperties(resource, resourceVO);
                    if (resource.getCreateTime() != null) {
                        resourceVO.setCreateTime(DateUtils
                                .getTimeStampStr(resource.getCreateTime()));
                    }
                    if (resource.getUpdateTime() != null) {
                        resourceVO.setUpdateTime(DateUtils
                                .getTimeStampStr(resource.getUpdateTime()));
                    }
                    resourceVO.setIsDelete(ConstantMapKey.IS_DELETE
                            .get(resource.getIsDelete()));
                    resourceVO.setType(ConstantMapKey.IM_CENTER_RESOURCE_TYPE
                            .get(resource.getType()));
                    list.add(resourceVO);
                }
                vo.setList(list);
            }
            vo.setCount(page.getTotal());
        }
        return vo;
    }
}
